import myApi from '@/utils/app.js';
export const request = (options) => {
	return new Promise((resolve, reject) => {
		if (!options.url) {
			console.error('请传入URL')
			return;
		}
		sendRequest(options, resolve, reject);
	})
};

function sendRequest(options, resolve, reject, retryCount) { //封装的发送请求函数
	// const token = uni.getStorageSync('token');
	uni.request({
		url: options.url,
		data: options.data || {},
		method: options.method || 'POST',
		// header: {
		// 	"X-Access-Token": token,
		// },
		timeout: 10000, // 设置请求超时时间为10秒
		success: (res) => {
			console.log(res)
			if(res.data.code == 200 || res.data.code == 500 || res.data.code == 201)resolve(res.data);else reject(res.data)
		},
		fail: (err) => {
			// 请求失败，抛出错误
			reject(err);
		}
	});
}